const mongoose = require('mongoose')
const { preSave } = require('../utils')

const userSchema = new mongoose.Schema({
    account: String,
    password: String,
    roleId: String,

    meta: {
        createAt: {
            type: Number,
            default: (new Date()).getTime(),
        },
        updateAt: {
            type: Number,
            default: (new Date()).getTime(),
        },
    },
})

const InviteCodeSchema = new mongoose.Schema({
    code: String, // 邀请码
    userID: String, // 用来注册哪个用户

    meta: {
        createAt: {
            type: Number,
            default: (new Date()).getTime(),
        },
        updateAt: {
            type: Number,
            default: (new Date()).getTime(),
        },
    },
})

userSchema.pre('save', preSave)

module.exports = { userSchema, InviteCodeSchema }
